import { Album, generateAlbums } from "@/faker/album/albums";
import { generateUserArtists, IUserArtist } from "@/faker/user/user";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";

export const fetchRecommendAlbums = createAsyncThunk("Albums",async (arg,{dispatch})=>{
    const res = await generateAlbums(50)
    dispatch(changeAlbumsAction(res))
})

export const fetchRecommendArtists = createAsyncThunk("Artists",async (arg,{dispatch})=>{
    const res = await generateUserArtists(50)
    dispatch(changeArtistsAction(res))
})
export const fetchRecommendMvs = createAsyncThunk("Mvs",async (arg,{dispatch})=>{
    const res = await generateAlbums(50)
    dispatch(changeMvsAction(res))
})
interface IState {

    albums: Album[],
    artists: IUserArtist[],
    mvs:Album[],
}

const initialState: IState = {
    albums: [],
    artists: [],
    mvs:[]
}
        
const recommendSlice = createSlice({
    name: "recommend",
    initialState,
    reducers: {
        changeAlbumsAction(state,{payload}){
            state.albums = payload
        },
        changeArtistsAction(state,{payload}){
            state.artists = payload
        },
        changeMvsAction(state,{payload}){
            state.mvs = payload
        }
 
    }
})

export const {changeAlbumsAction,changeArtistsAction,changeMvsAction} = recommendSlice.actions

export default recommendSlice.reducer

